home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / termsorc.lha / Extras / Source / gtlayout-source.lha / LT_LabelWidth.c < prev    next >
C/C++ Source or Header  |  1995-09-24  |  1KB  |  81 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1995 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. */
  6.  
  7. #include "gtlayout_global.h"
  8.  
  9. LONG LIBENT
  10. LT_LabelWidth(REG(a0) LayoutHandle *handle,REG(a1) STRPTR label)
  11. {
  12.     if(handle)
  13.     {
  14.         struct RastPort    *rp = &handle -> RPort;
  15.         LONG    start;
  16.         LONG    len;
  17.         LONG    cnt;
  18.         LONG    width,maxWidth;
  19.         LONG    underscore;
  20.  
  21.         start = 0;
  22.         maxWidth = 0;
  23.         underscore = 0;
  24.  
  25.         cnt = 0;
  26.         len = 0;
  27.  
  28.         while(label[len])
  29.         {
  30.             if(label[len] == '_')
  31.             {
  32.                 if(!underscore)
  33.                     underscore = TextLength(rp,"_",1);
  34.  
  35.                 cnt += underscore;
  36.             }
  37.  
  38.             if(label[len] == '\n')
  39.             {
  40.                 if(len > start)
  41.                     width = TextLength(rp,&label[start],len - start) - cnt;
  42.                 else
  43.                     width = 0;
  44.  
  45.                 cnt = 0;
  46.                 start = len + 1;
  47.  
  48.                 if(width > maxWidth)
  49.                     maxWidth = width;
  50.             }
  51.  
  52.             len++;
  53.         }
  54.  
  55.         if(len > start)
  56.             width = TextLength(rp,&label[start],len - start) - cnt;
  57.         else
  58.             width = 0;
  59.  
  60.         if(width > maxWidth)
  61.             maxWidth = width;
  62.  
  63.         return(maxWidth);
  64.     }
  65.     else
  66.         return(0);
  67. }
  68.  
  69.  
  70. /*****************************************************************************/
  71.  
  72.  
  73. LONG LIBENT
  74. LT_LabelChars(REG(a0) LayoutHandle *handle,REG(a1) STRPTR label)
  75. {
  76.     if(handle)
  77.         return((LT_LabelWidth(handle,label) + handle -> GlyphWidth - 1) / handle -> GlyphWidth);
  78.     else
  79.         return(0);
  80. }
  81.